{% extends 'base/base.html' %}

{% block title %}项目标签 - {{ project.name }} - 多用户报警系统{% endblock %}

{% block content %}
<div class="mb-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1>
            <i class="fa fa-tags" aria-hidden="true"></i> 项目标签 - {{ project.name }}
        </h1>
        {% if user_role == 'admin' or user_role == 'developer' %}
            <a href="{% url 'projects:project_add_tag' project.id %}" class="btn btn-primary">
                <i class="fa fa-plus" aria-hidden="true"></i> 添加标签
            </a>
        {% endif %}
    </div>
    
    {% if tags %}
        <div class="row">
            {% for tag in tags %}
                <div class="col-md-4 mb-3">
                    <div class="card h-100">
                        <div class="card-body d-flex justify-content-between align-items-center">
                            <div>
                                <span class="tag" style="background-color: {{ tag.color }};">{{ tag.name }}</span>
                            </div>
                            {% if user_role == 'admin' or user_role == 'developer' %}
                                <a href="{% url 'projects:project_delete_tag' project.id tag.id %}" class="btn btn-danger btn-sm" title="删除标签" onclick="return confirm('确定要删除该标签吗？');">
                                    <i class="fa fa-trash" aria-hidden="true"></i>
                                </a>
                            {% endif %}
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
        
        <!-- 分页 -->
        {% if is_paginated %}
            <nav aria-label="Page navigation" class="mt-4">
                <ul class="pagination justify-content-center">
                    {% if page_obj.has_previous %}
                        <li class="page-item">
                            <a class="page-link" href="?page={{ page_obj.previous_page_number }}" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                    {% else %}
                        <li class="page-item disabled">
                            <a class="page-link" href="#" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                    {% endif %}
                    
                    {% for num in page_obj.paginator.page_range %}
                        {% if page_obj.number == num %}
                            <li class="page-item active"><a class="page-link" href="#">{{ num }}</a></li>
                        {% else %}
                            <li class="page-item"><a class="page-link" href="?page={{ num }}">{{ num }}</a></li>
                        {% endif %}
                    {% endfor %}
                    
                    {% if page_obj.has_next %}
                        <li class="page-item">
                            <a class="page-link" href="?page={{ page_obj.next_page_number }}" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    {% else %}
                        <li class="page-item disabled">
                            <a class="page-link" href="#" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    {% endif %}
                </ul>
            </nav>
        {% endif %}
    {% else %}
        <div class="card">
            <div class="card-body text-center py-8">
                <i class="fa fa-tag" aria-hidden="true" style="font-size: 4rem; color: #d9d9d9;"></i>
                <h3 class="mt-4 text-muted">暂无项目标签</h3>
                <p class="text-muted mb-6">标签可以帮助您更好地组织和分类项目内容</p>
                {% if user_role == 'admin' or user_role == 'developer' %}
                    <a href="{% url 'projects:project_add_tag' project.id %}" class="btn btn-primary">
                        <i class="fa fa-plus" aria-hidden="true"></i> 添加第一个标签
                    </a>
                {% endif %}
            </div>
        </div>
    {% endif %}
</div>
{% endblock %}

{% block javascript %}
<script>
    // 添加页面加载动画效果
    document.addEventListener('DOMContentLoaded', function() {
        // 为标签添加悬停效果
        const tags = document.querySelectorAll('.tag');
        tags.forEach(tag => {
            tag.addEventListener('mouseenter', function() {
                this.style.transform = 'scale(1.1)';
                this.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.2)';
            });
            tag.addEventListener('mouseleave', function() {
                this.style.transform = 'scale(1)';
                this.style.boxShadow = 'none';
            });
        });
        
        // 为卡片添加悬停效果
        const cards = document.querySelectorAll('.card');
        cards.forEach(card => {
            card.addEventListener('mouseenter', function() {
                this.style.transform = 'translateY(-2px)';
                this.style.boxShadow = '0 4px 16px rgba(0, 0, 0, 0.12)';
            });
            card.addEventListener('mouseleave', function() {
                this.style.transform = 'translateY(0)';
                this.style.boxShadow = '0 2px 8px rgba(0, 0, 0, 0.08)';
            });
        });
        
        // 为删除按钮添加确认提示
        const deleteButtons = document.querySelectorAll('.btn-danger');
        deleteButtons.forEach(button => {
            button.addEventListener('click', function(e) {
                if (!confirm('确定要删除该标签吗？')) {
                    e.preventDefault();
                }
            });
        });
    });
</script>
{% endblock %}